package com.csu.soa_library.service.Impl;

import com.csu.soa_library.dao.BookRepository;
import com.csu.soa_library.entity.Book;
import com.csu.soa_library.service.BookService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @author YiGongLily
 * @version V1.0
 * Copyright (c) 2024, bie blind copy all thing fine.
 * @ProjectName:soa_library
 * @Title: BookServiceImpl
 * @Package com.csu.soa_library.service.Impl
 * @Description: bookImpl
 * @date 2024/11/25 23:01
 */
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookRepository bookRepository;

    @Override
    public void addBook(Book book) {
        bookRepository.save(book);
    }

    @Override
    public void deleteBook(int bookId) {
        bookRepository.deleteById(bookId);
    }

    @Override
    public void updateBook(Book book) {
        bookRepository.save(book);
    }

    @Override
    public org.springframework.data.domain.Page getBookList(int pageNum, int pageSize) {
        Pageable pageable = PageRequest.of(pageNum, pageSize);
        return bookRepository.findAll(pageable);
    }

    @Override
    public Book getBookById(int bookId) {
        return bookRepository.findById(bookId).orElse(null);
    }
}
